package org.planaz.campusvoting.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import org.planaz.campusvoting.common.result.Result;
import org.planaz.campusvoting.dto.req.UserQueryReq;
import org.planaz.campusvoting.dto.req.UserRegisterReq;
import org.planaz.campusvoting.pojo.User;
import org.planaz.campusvoting.service.UserService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api/v1/users")
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping("/login")
    public Result<?> login(String username, String password) {
        return userService.login(username, password);
    }

    @RequestMapping("/register")
    public Result<?> register(@RequestBody UserRegisterReq userRegisterReq) {
        return userService.register(userRegisterReq);
    }

    @RequestMapping("/loginByEmail")
    public Result<?> loginByEmail(String email, String code) {
        return userService.loginByEmail(email, code);
    }

    @RequestMapping("/registerByEmail")
    public Result<?> registerByEmail(String email, String password, String code) {
        return userService.registerByEmail(email, password, code);
    }

    @RequestMapping("/resetPasswordByEmail")
    public Result<?> resetPasswordByEmail(String email, String password, String code) {
        return userService.resetPasswordByEmail(email, password, code);
    }

    @RequestMapping("/resetPassword")
    public Result<?> resetPassword(String password) {
        return userService.resetPassword(password);
    }

    @RequestMapping("/resetEmail")
    public Result<?> resetEmail(String email, String code) {
        return userService.resetEmail(email, code);
    }

    @RequestMapping("/getUserInfo")
    public Result<?> getUserInfo() {
        return userService.getUserInfo();
    }

    @RequestMapping("/changeUserInfo")
    public Result<?> changeUserInfo(@RequestBody User userInfo) {
        return userService.changeUserInfo(userInfo);
    }

    @RequestMapping("/query")
    public Result<?> query(@RequestParam int page,@RequestParam int pageSize,@RequestBody(required = false) UserQueryReq userQueryReq){
        return userService.query(new Page<>(page, pageSize),userQueryReq);
    }

    @RequestMapping("/ban")
    public Result<?> ban(@RequestParam Long id){
        return userService.ban(id);
    }

    @RequestMapping("/unBan")
    public Result<?> unBan(@RequestParam Long id){
        return userService.unBan(id);
    }
}
